//声明一个模块，包含IntegratCtrl这个cotroller
angular.module("my-integrat-controller",[])

  .controller("IntegratCtrl",function($scope,$state,Storage,IntegratServiceCtrl){

  var memberId;



  //进入我的首页，进行数据加载
  $scope.$on('$ionicView.beforeEnter', function () {
    memberId = Storage.get("member").member_id;
    IntegratServiceCtrl.getIntegrat(memberId);
  });


  $scope.$on("IntegratServiceCtrlUpdata",function(){
    var result = IntegratServiceCtrl.getRuleJson();
    $scope.mePoint = result.mePoint;
    //对数据的加减分进行处理
    var list = result.ruleList;
    for(var i=0;i<list.length;i++){
      var point = list[i].pr_point;
      if(point > 0 ){
        list[i].pr_point = "+"+point;
      }
    }
    $scope.ruleList = list;
    for(i=0;i<$scope.ruleList.length;i++){
      var rule = $scope.ruleList[i].pr_name;
      if(rule.length>20){
        $scope.ruleList[i].pr_name = rule.substring(0,20)+"<br/>"+rule.substring(20);
      }
    }
  });


    $scope.gotoMyPointDetail = function () {
      $state.go('my-integrat-detail');
    }



});


